#pragma once

#include <AVUIFrameworkElement.h>
#include <AVUIIUriContext.h>

namespace AVUI {

class Renderer;
class IClientMediaElement;
class Uri;
class MediaElement : public FrameworkElement, public IUriContext
{
    friend class Visual;
public:
    DECLARE_ELEMENT(MediaElement, FrameworkElement);

    DECLARE_DEPENDENCY_PROPERTY_BEGIN(Source);
        DECLARE_ATTRIBUTE_CONTENTPROPERTY();
    DECLARE_DEPENDENCY_PROPERTY_END();
    TRefCountedPtr<Uri> get_Source() { return (Uri*)(Object*)GetValue(get_SourceProperty()); }
    void set_Source(Uri* pValue) { return SetValue(get_SourceProperty(), (Object*)pValue); }

    DECLARE_DEPENDENCY_PROPERTY(Volume);
    float get_Volume() { return AVUI::UnboxValue<float>(GetValue(get_VolumeProperty())); }
    void set_Volume(float value) { SetValue(get_VolumeProperty(), AVUI::BoxValue(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(Stretch);
    Stretch::Enum get_Stretch() { return (Stretch::Enum)(AVUI::UnboxValue<int>(GetValue(get_StretchProperty()))); }
    void set_Stretch(Stretch::Enum value) { SetValue(get_StretchProperty(), AVUI::BoxValue<int>(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(StretchDirection);
    StretchDirection::Enum get_StretchDirection() { return (StretchDirection::Enum)(AVUI::UnboxValue<int>(GetValue(get_StretchDirectionProperty()))); }
    void set_StretchDirection(StretchDirection::Enum value) { SetValue(get_StretchDirectionProperty(), AVUI::BoxValue<int>(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(BaseUri);
    TRefCountedPtr<Uri> get_BaseUri() { return (Uri*)(Object*)GetValue(get_BaseUriProperty()); }
    void set_BaseUri(Uri* pValue) { return SetValue(get_BaseUriProperty(), (Object*)pValue); }

    MediaElement();
    ~MediaElement();

    Size MeasureOverride(const Size& constraintSize);
    Size ArrangeOverride(const Size& constraintSize);

protected:
    virtual void OnVisualParentChanged(DependencyObject* pOldParent);


private:
    static void StaticConstructor();
    static void OnVolumeChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);


    void RenderMedia(Renderer* pRenderer);
    virtual void OnRender(DrawingContext& drawingContext);

    IClientMediaElement* m_pClientMediaElement;
};



}; // namespace AVUI
